﻿using System;
using System.Web.Mvc;
using System.Web.Routing;

namespace RecruitmentAgency.Models.Utilities.Paging
{
    /// <summary>
    /// The RecruitmentAgency.Models.Cv.DataTypes.PagingExtensions 
    /// </summary>
    public static class PagingExtensions
    {
        #region HtmlHelper extensions

        /// <summary>
        /// 
        /// </summary>
        /// <param name="htmlHelper">An HtmlHelper instance used to generate html</param>
        /// <param name="pageSize">The number of records to display</param>
        /// <param name="currentPage">The current page</param>
        /// <param name="totalItemCount">The total number of records</param>
        /// <returns>A html pager</returns>
        public static string Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount)
        {
            return Pager(htmlHelper, pageSize, currentPage, totalItemCount, null, null);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <param name="pageSize">The number of records to display</param>
        /// <param name="currentPage">The current page</param>
        /// <param name="totalItemCount">The total number of records</param>
        /// <param name="actionName">The action to perform</param>
        /// <param name="valuesDictionary"></param>
        /// <returns>A html pager</returns>
        public static string Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, string actionName, RouteValueDictionary valuesDictionary)
        {
            if (valuesDictionary == null)
            {
                valuesDictionary = new RouteValueDictionary();
            }
            if (actionName != null)
            {
                if (valuesDictionary.ContainsKey("action"))
                {
                    throw new ArgumentException("The valuesDictionary already contains an action.", "actionName");
                }
                valuesDictionary.Add("action", actionName);
            }
            var pager = new Pager(htmlHelper.ViewContext, pageSize, currentPage, totalItemCount, valuesDictionary);
            return pager.RenderHtml();
        }

        #endregion
    }
}
